extends Panel

signal complete
signal on_select

@onready var item_list: ItemList = $VBox/ItemList
@onready var button: Button = $VBox/Button
@onready var close: Button = $Close

var current_data : String

func _ready() -> void:
	_on_close()
	item_list.item_selected.connect(func(index:int):current_data = item_list.get_item_text(index))
	button.button_up.connect(on_select.emit)
	close.button_up.connect(_on_close)

func _init_data_sync(data : Array) -> Signal :
	show()
	for item in data :
		if not item.begins_with("design_") : continue
		item_list.add_item(item)
	await on_select
	return complete

func _get_result() -> String :
	call_deferred("_on_close")
	return current_data

func _on_close() -> void :
	item_list.clear()
	hide()
